package models;

import play.db.ebean.Model;
import play.db.ebean.Model.Finder;

import javax.persistence.*;

import com.avaje.ebean.Page;
import com.avaje.ebean.validation.NotNull;

@Entity
public class SoilCategory extends Model{
	
	@Id
	public Long id;
	
	@NotNull
	public String soilKey;
	
	//Finder
	public static Finder<Long, SoilCategory> find = new Finder<Long, SoilCategory>(
			Long.class, SoilCategory.class);
	
	public static SoilCategory getSoilCategory(SoilCategory soilCategory) {
		return find.fetch("soilCategory").where().idEq(soilCategory.id).findUnique();
	}
	
    /**
     * Return a page of SoilCategory
     *
     * @param page Page to display
     * @param pageSize Number of computers per page
     * @param sortBy Computer property used for sorting
     * @param order Sort order (either or asc or desc)
     * @param filter Filter applied on the name column
     */
	
    public static Page<SoilCategory> page(int page, int pageSize, String sortBy, String order, String filter) {
        return 
            find.where()
                .ilike("name", "%" + filter + "%")
                .orderBy(sortBy + " " + order)
                .findPagingList(pageSize)
                .getPage(page);
    }
}
